<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        td{
            width: 80px;
            height: 30px;
            font-size: 10px;
            line-height: 30px;
        }
    </style>
    <script>
        var arr = new Array()
        arr[0] = "第1页内容";
        arr[1] = "第2页内容";
        arr[2] = "第3页内容";
        arr[3] = "第4页内容";
        arr[4] = "第5页内容";
        function f(val) {
            if (document.getElementById(val).innerHTML=="上一页"){
                var y = parseInt(document.getElementById("ys").innerHTML);
                if (y>1 && y<6){
                    y-=1;
                    var brr = document.getElementsByTagName("td");
                    for (var i = 0; i < brr.length; i++) {
                        brr[i].innerHTML = arr[y-1];
                    }
                    document.getElementById("ys").innerHTML = y;
                } else{
                    if (y==1){
                        alert("已经到头了!")
                    } else {
                        alert("已经到底了!")
                    }
                }
            }else {
                var y = parseInt(document.getElementById("ys").innerHTML);
                if (y>0 && y<5){
                    var crr = document.getElementsByTagName("td");
                    for (var i1 = 0; i1 < crr.length; i1++) {
                        crr[i1].innerHTML = arr[y];
                    }
                    y+=1;
                    document.getElementById("ys").innerHTML = y;
                }else{
                    if (y==1){
                        alert("已经到头了!")
                    } else {
                        alert("已经到底了!")
                    }
                }
            }
        }
    </script>
</head>
<body>
    <h2>使用js对表格内容进行分页</h2>
    <table border="1"cellpadding="1"cellspacing="2">
        <tr>
            <td>第1页内容</td>
            <td>第1页内容</td>
        </tr>
        <tr>
            <td>第1页内容</td>
            <td>第1页内容</td>
        </tr>
    </table><br>
    总页数5&nbsp;当前页<font id="ys">1</font><button style="margin-right: 5px" id="s" onclick="f(this.id)">上一页</button><button id="x" onclick="f(this.id)">下一页</button>
</body>
</html>